#include <stx/imp/cmn.hpp>

inline namespace stx
{
GLOBAL_VAR(gStdOutErrMtx__, std::recursive_mutex{});

Cout__::Cout__(std::ostream& (*manipulator)(std::ostream&))
    : fn_task([=] { manipulator(std::cout); })
{}

Cerr__::Cerr__(std::ostream& (*manipulator)(std::ostream&))
    : fn_task([=] { manipulator(std::cerr); })
{}

void cout__(auto const& head, auto const&... tail)
{
    LOCK(gStdOutErrMtx__());
    (head.fn_task(), ..., tail.fn_task());
    std::cout << std::flush;
}

void cerr__(auto const& head, auto const&... tail)
{
    LOCK(gStdOutErrMtx__());
    (head.fn_task(), ..., tail.fn_task());
    std::cerr << std::flush;
}

void xout()
{
    LOCK(gStdOutErrMtx__());
    std::cout << std::endl;
}

void xerr()
{
    LOCK(gStdOutErrMtx__());
    std::cerr << std::endl;
}

void cout(Cout__ v1)
{
    cout__(v1);
}

void cout(Cout__ v1, Cout__ v2)
{
    cout__(v1, v2);
}

void cout(Cout__ v1, Cout__ v2, Cout__ v3)
{
    cout__(v1, v2, v3);
}

void cout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4)
{
    cout__(v1, v2, v3, v4);
}

void cout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4, Cout__ v5)
{
    cout__(v1, v2, v3, v4, v5);
}

void cout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4, Cout__ v5, Cout__ v6)
{
    cout__(v1, v2, v3, v4, v5, v6);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7)
{
    cout__(v1, v2, v3, v4, v5, v6, v7);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13,
          Cout__ v14)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13,
          Cout__ v14,
          Cout__ v15)
{
    cout__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
}

void cout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13,
          Cout__ v14,
          Cout__ v15,
          Cout__ v16)
{
    cout__(
        v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16);
}

void xout(Cout__ v1)
{
    cout(v1, '\n');
}

void xout(Cout__ v1, Cout__ v2)
{
    cout(v1, v2, '\n');
}

void xout(Cout__ v1, Cout__ v2, Cout__ v3)
{
    cout(v1, v2, v3, '\n');
}

void xout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4)
{
    cout(v1, v2, v3, v4, '\n');
}

void xout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4, Cout__ v5)
{
    cout(v1, v2, v3, v4, v5, '\n');
}

void xout(Cout__ v1, Cout__ v2, Cout__ v3, Cout__ v4, Cout__ v5, Cout__ v6)
{
    cout(v1, v2, v3, v4, v5, v6, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7)
{
    cout(v1, v2, v3, v4, v5, v6, v7, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13,
          Cout__ v14)
{
    cout(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, '\n');
}

void xout(Cout__ v1,
          Cout__ v2,
          Cout__ v3,
          Cout__ v4,
          Cout__ v5,
          Cout__ v6,
          Cout__ v7,
          Cout__ v8,
          Cout__ v9,
          Cout__ v10,
          Cout__ v11,
          Cout__ v12,
          Cout__ v13,
          Cout__ v14,
          Cout__ v15)
{
    cout(
        v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, '\n');
}

void cerr(Cerr__ v1)
{
    cerr__(v1);
}

void cerr(Cerr__ v1, Cerr__ v2)
{
    cerr__(v1, v2);
}

void cerr(Cerr__ v1, Cerr__ v2, Cerr__ v3)
{
    cerr__(v1, v2, v3);
}

void cerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4)
{
    cerr__(v1, v2, v3, v4);
}

void cerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4, Cerr__ v5)
{
    cerr__(v1, v2, v3, v4, v5);
}

void cerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4, Cerr__ v5, Cerr__ v6)
{
    cerr__(v1, v2, v3, v4, v5, v6);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13,
          Cerr__ v14)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13,
          Cerr__ v14,
          Cerr__ v15)
{
    cerr__(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
}

void cerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13,
          Cerr__ v14,
          Cerr__ v15,
          Cerr__ v16)
{
    cerr__(
        v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16);
}

void xerr(Cerr__ v1)
{
    cerr(v1, '\n');
}

void xerr(Cerr__ v1, Cerr__ v2)
{
    cerr(v1, v2, '\n');
}

void xerr(Cerr__ v1, Cerr__ v2, Cerr__ v3)
{
    cerr(v1, v2, v3, '\n');
}

void xerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4)
{
    cerr(v1, v2, v3, v4, '\n');
}

void xerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4, Cerr__ v5)
{
    cerr(v1, v2, v3, v4, v5, '\n');
}

void xerr(Cerr__ v1, Cerr__ v2, Cerr__ v3, Cerr__ v4, Cerr__ v5, Cerr__ v6)
{
    cerr(v1, v2, v3, v4, v5, v6, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13,
          Cerr__ v14)
{
    cerr(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, '\n');
}

void xerr(Cerr__ v1,
          Cerr__ v2,
          Cerr__ v3,
          Cerr__ v4,
          Cerr__ v5,
          Cerr__ v6,
          Cerr__ v7,
          Cerr__ v8,
          Cerr__ v9,
          Cerr__ v10,
          Cerr__ v11,
          Cerr__ v12,
          Cerr__ v13,
          Cerr__ v14,
          Cerr__ v15)
{
    cerr(
        v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, '\n');
}
} // namespace stx